<template>
	<view>
		<swiper class="card-swiper" :class="dotStyle?'square-dot':'round-dot'" :indicator-dots="true" :circular="true"
			:autoplay="true" interval="5000" duration="500" @change="cardSwiper" indicator-color="#8799a3"
			indicator-active-color="#0081ff">
			<swiper-item v-for="(item,index) in info.imagePath" :key="index" :class="cardCur==index?'cur':''">
				<view class="swiper-item">
					<image :src="item" mode="aspectFill"></image>
					<video :src="item" autoplay loop muted :show-play-btn="false" :controls="false" objectFit="cover"
						v-if="item.type=='video'"></video>
				</view>
			</swiper-item>
		</swiper>

		<!--  -->
		<view class="detail_content   padding-lr" style="margin-top: 20rpx;">
			<view class="padding-lr bg-white">
				<view class="solid-bottom padding">
					<text class="text-black text-bold" style="font-size: 40rpx;">{{info.activity.activityname}}</text>
				</view>
				<view class="padding">
					{{info.activity.detail}}
				</view>
			</view>
		</view>
		<view class="detail_content   padding-lr" style="margin-top: 20rpx;">
			<view class="padding-lr padding radius  light bg-white">
				<view class="solid-bottom padding">
					<text class="text-black text-bold" style="font-size: 40rpx;">时间：</text>
				</view>
				<view class="padding">报名开始时间：{{info.activity.applyendtime}}---{{info.activity.applystarttime}}</view>
				<view class="padding">活动时间：{{info.activity.begintime}}---{{info.activity.endtime}}</view>

			</view>
		</view>

		<view class="detail_content   padding-lr" style="margin-top: 20rpx;">
			<view class="padding-lr padding radius  light bg-white">
				<view class="solid-bottom padding">
					<text class="text-black text-bold" style="font-size: 40rpx;">地点：</text>
				</view>
				<view class="padding">{{info.activity.address}}</view>
			</view>
		</view>


		<view class="detail_content   padding-lr" style="margin-top: 20rpx;">
			<view class="padding-lr bg-white ">
				<view class="solid-bottom padding">
					<text class="text-black text-bold" style="font-size: 40rpx;">报名人数：</text>
				</view>
				<view class="padding">{{info.activity.participant}}人</view>
			</view>
		</view>
		<button @tap="apply" class=" round bg-yellow     lg" style="margin: 30rpx;">活动报名</button>
		<downblock></downblock>


	</view>

</template>

<script>
	import downblock from '../../components/down_block.vue'
	export default {
		data() {
			return {
				cardCur: 0,
				dotStyle: true,
				info: {},
				baseurl: '',
				activityName: ''
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
		this.getData(option.name)
		},

		components: {
			downblock
		},
		methods: {
			async apply() {
				// 获取用户名
				const ret = uni.getStorageSync("USERS_KEY");
				// 对数据进行反序列化
				const res = JSON.parse(ret)
				let username = res.username;
				uni.request({
					method: "GET",
					url: this.baseurl + '/Audit/applyAct?activityName=' + this.info.activity.activityname +
						"&userName=" + username,
					success: (res) => {
						uni.showToast({
							title: res.data,
							icon: null
						});
						if(res.statusCode==200){
							uni.reLaunch({
								url:"../index/index"
							})
						}
					},
					complete() {
						
					}
				})
			},
			
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},

			async getData(name) {
				
				
				const baseurl=getApp().globalData.BASE_URL
				let inner=this
				uni.request({
					url:baseurl+'/activity/getDetail?name='+ name,
					success: (res) => {
						inner.info = res.data
						inner.baseurl = getApp().globalData.BASE_URL
						// 装换数据
						for (let i = 0; i < inner.info.imagePath.length; i++) {
							if (inner.info.imagePath[i].indexOf("http") == -1) {
								// 如果图片url里面没有http字体那边加上baseurl
								inner.info.imagePath[i] = inner.baseurl + inner.info.imagePath[i];
						
							}
						}
					}
				})
				
				// const res = await this.$myRequest({
				// 	url: `/activity/getDetail?name=` + name
				// });
				// this.activityName=name
				// this.info = res.data
				// this.baseurl = getApp().globalData.BASE_URL
				// // 装换数据
				// for (let i = 0; i < this.info.imagePath.length; i++) {
				// 	if (this.info.imagePath[i].indexOf("http") == -1) {
				// 		// 如果图片url里面没有http字体那边加上baseurl
				// 		this.info.imagePath[i] = this.baseurl + this.info.imagePath[i];

				// 	}
				// }
			}
		}
	}
</script>

<style>

</style>
